import Vue from "vue";
import VueRouter from "vue-router";

Vue.use(VueRouter);

// 公共路由
export const constantRoutes = [
  {
    path: "/",
    redirect: "/home"
  },
  {
    path: "/home",
    component: () => import("@/views/Home.vue"),
    name: "Home",
    meta: {
      title: "首页"
    }
  },
  {
    path: "/handWrittenSignature",
    component: () => import("@/views/handWrittenSignature.vue"),
    name: "handWrittenSignature",
    meta: {
      title: "手写签名"
    }
  }
];

// 动态路由，基于用户权限动态去加载
export const dynamicRoutes = [];

// 防止连续点击多次路由报错
let routerPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
  return routerPush.call(this, location).catch(err => err);
};

export default new VueRouter({
  base: process.env.VUE_APP_CONTEXT_PATH,
  mode: "history", // 去掉url中的#
  scrollBehavior: () => ({
    y: 0
  }),
  routes: constantRoutes
});